package com.tuling.jucdemo.threadpool;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author :tangweiliang
 * @date : 2022/11/21 20:54
 * 未来的你会感谢现在努力的自己
 *
 * 使用线程的方式去执行程序
 * //10000个线程 10000个对象
 */
public class ThreadTest {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        final Random random = new Random();
        final List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < 100000; i++) {
            Thread thread = new Thread(new Runnable(){
                @Override
                public void run() {
                    list.add(random.nextInt());
                }
            });
            thread.start();//10000个线程 10000个对象
            thread.join();
        }
        System.out.println("执行时间:"+(System.currentTimeMillis() - start));
        System.out.println("list:" + list.size());
    }
}
